/*
 * Copyright (c) 2012-2020 MIRACL UK Ltd.
 *
 * This file is part of MIRACL Core
 * (see https://github.com/miracl/core).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//
//  rom.swift
//
//  Created by Michael Scott on 12/06/2015.
//  Copyright (c) 2015 Michael Scott. All rights reserved.
//

import core

public struct ROM{
 
#if D32

// Base Bits= 28
static let Modulus:[Chunk] = [0x138013,0x1B0084,0x24,0xF640000,0xC6FF687,0xF6FF66F,0xFFFFFFF,0xC8020FF,0x2908F41,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]
static let ROI:[Chunk] = [0x138012,0x1B0084,0x24,0xF640000,0xC6FF687,0xF6FF66F,0xFFFFFFF,0xC8020FF,0x2908F41,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]
static let R2modp:[Chunk] = [0x88F9612,0xC8B9999,0x247088C,0xDB3ACD5,0xCA792EF,0x6E92E73,0x34F5999,0x4273E13,0x6714A6A,0xCBFE239,0xA0E2617,0x2487CB3,0xBE0EA3C,0x97791E4,0x8A07DE5,0x56CFA97,0x373]
static let MConst:Chunk = 0x11BB5E5
static let SQRTm3:[Chunk] = [0x210022,0x2400CC,0x24,0xEF80000,0xB07F12F,0xF6FF4BF,0xFFFFFFF,0x7C032FF,0x440AEC2,0xD81,0x8000000,0xDFD2FFB,0x6FF03F5,0xFFFFFFF,0x23FFF,0x8036012,0x2404]
static public let Fra:[Chunk] = [0x2575D1A,0xE4BE3FF,0x659DBDE,0xFC7D89,0x93FA118,0xD45D1D,0xCC78D9,0x6217331,0xD547C05,0xC792504,0x9A87E11,0x92ED03A,0x1727085,0xB5A8CC1,0xB40BCFD,0xF4348CB,0x16F]
static public let Frb:[Chunk] = [0x55FF85B,0x204AE09,0x57BEB62,0x9023886,0xD630A20,0xF94F4B,0x84FF0D0,0x14A1A7A,0xB1DBADB,0xB00D8E4,0x1E85F7,0x7493CA0,0x68325B2,0x2008E6B,0xE90EA88,0x7F80940,0x23C3]

//*** rom curve parameters *****
// Base Bits= 28
// Ate Bits= 118
// G2 Table size= 125

static let CURVE_Cof_I:Int = 1
static public let CURVE_Cof:[Chunk] = [0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static let CURVE_B_I:Int = 5
static public let CURVE_B:[Chunk] = [0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static public let CURVE_Order:[Chunk] = [0x10800D,0x1B007E,0x24,0xF7C0000,0xC7BF717,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]
static public let CURVE_Gx:[Chunk] = [0x6B6980D,0x98D91F3,0xD70113C,0x372E5C,0xE79239C,0x416A0B1,0xBB4E69A,0x689DB1B,0x3CF4B2E,0xB3EDBEC,0x6F95F63,0xAC9264B,0x30160B9,0xBA34A0A,0x191FAD,0xD67EF25,0x21A6]
static public let CURVE_Gy:[Chunk] = [0x6FB03DE,0xA5734D3,0x22ECAA8,0xC666006,0xF475432,0xE40EB80,0xDF11B8A,0x6E6AF77,0x5965042,0x7D788C6,0x42CCCFA,0x90EEDA8,0xA7432A4,0x2B33676,0x7F7ABB8,0xEA0460F,0x118]
static public let CURVE_HTPC:[Chunk] = [0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static public let CURVE_Bnx:[Chunk] = [0xFFFBFFF,0xFFFFFFF,0xFFFFFFF,0x1FFFF,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static public let CRu:[Chunk] = [0x1A401A,0x1F80A8,0x24,0xF2E0000,0xBBBF3DB,0xF6FF597,0xFFFFFFF,0x22029FF,0x3689F02,0xD81,0x1000000,0x4BD65FC,0x6FF0876,0xFFFFFFF,0x23FFF,0x8036012,0x2404]
static public let CURVE_Pxa:[Chunk] = [0xAE1E4DF,0x8E3D934,0x769546,0x6A8B488,0xAE1F0AA,0x92E0032,0x2699BAD,0x208F9AD,0x3820408,0xED61C91,0x7C1CD96,0x2E0337E,0xCBDC548,0xB38E3A8,0x8DDA0DF,0xCCC85B5,0x257]
static public let CURVE_Pxb:[Chunk] = [0xA8CD283,0x108BA6A,0x50E9B73,0x59BF7E8,0xF50AF8B,0xB783718,0x6BAE555,0x8134DD8,0x84058B1,0xED91768,0x54730CB,0xC98E2A3,0x9566BA3,0x8EDCA84,0x99102AF,0x4343E85,0x1D2E]
static public let CURVE_Pya:[Chunk] = [0xDB7154E,0x5B68DF0,0x7C3376E,0xE7B11D,0x3695A14,0xDAE32E0,0x1F41C9D,0xF1399A,0xB42FE81,0x3FA7A6B,0x706E23C,0xA035634,0x20809EC,0x517427A,0x22C1979,0x50439DA,0xA06]
static public let CURVE_Pyb:[Chunk] = [0xCA2A93A,0x14CC552,0x93B9EBA,0xD537434,0x387AA68,0xA04EF87,0x7692444,0x725CC64,0xAB370FD,0x7B393F1,0xC69AC5,0x44D5E6B,0x306324D,0x2C8AE37,0x8CBE017,0xF0CBD43,0x73E]
static let CURVE_W:[[Chunk]] = [[0x20003,0x6,0x0,0xFF00000,0xFF3FF7F,0xFFFFFFF,0xFFFFFFF,0x60017F,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFF7FFF,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]]
static let CURVE_SB:[[[Chunk]]] = [[[0x28004,0x6,0x0,0xFEC0000,0xFF3FF77,0xFFFFFFF,0xFFFFFFF,0x60017F,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x11000E,0x1B007E,0x24,0xF780000,0xC7BF70F,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]],[[0xFFF7FFF,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x20003,0x6,0x0,0xFF00000,0xFF3FF7F,0xFFFFFFF,0xFFFFFFF,0x60017F,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]]]
static let CURVE_WB:[[Chunk]] = [[0x4000,0x2,0x0,0xFFE0000,0xFFBFFDB,0xFFFFFFF,0xFFFFFFF,0x20007F,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFABFFB,0xFFCFFE3,0xFFFFFFF,0x29FFFF,0x800214,0x90,0x0,0xBFFF900,0xF6FF53F,0xFFFFFFF,0x5FFFFFF,0x4802400,0x300,0x0,0x0,0x0,0x0],[0xFFD3FFD,0xFFE7FF1,0xFFFFFFF,0x15FFFF,0x40010C,0x48,0x0,0xDFFFC80,0xFB7FA9F,0xFFFFFFF,0x2FFFFFF,0x2401200,0x180,0x0,0x0,0x0,0x0],[0xC001,0x2,0x0,0xFFA0000,0xFFBFFD3,0xFFFFFFF,0xFFFFFFF,0x20007F,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]]
static let CURVE_BB:[[[Chunk]]] = [[[0xFFFC000,0xFFFFFFF,0xFFFFFFF,0x1FFFF,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFBFFF,0xFFFFFFF,0xFFFFFFF,0x1FFFF,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFBFFF,0xFFFFFFF,0xFFFFFFF,0x1FFFF,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x11000F,0x1B007E,0x24,0xF780000,0xC7BF70F,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]],[[0xFFF7FFF,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x10C00E,0x1B007E,0x24,0xF7A0000,0xC7BF713,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404],[0x10C00D,0x1B007E,0x24,0xF7A0000,0xC7BF713,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404],[0x10C00E,0x1B007E,0x24,0xF7A0000,0xC7BF713,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]],[[0xFFF7FFE,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFF7FFF,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFF7FFF,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFF7FFF,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]],[[0x10C00F,0x1B007E,0x24,0xF7A0000,0xC7BF713,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404],[0x11800F,0x1B007E,0x24,0xF740000,0xC7BF707,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404],[0xFFF7FFD,0xFFFFFFF,0xFFFFFFF,0x3FFFF,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x10C00F,0x1B007E,0x24,0xF7A0000,0xC7BF713,0xF6FF66F,0xFFFFFFF,0xC201F7F,0x2908EE1,0xD81,0xA000000,0xB7D9BFC,0x6FF0CF6,0xFFFFFFF,0x23FFF,0x8036012,0x2404]]]

#endif

#if D64

// Base Bits= 60
static let Modulus:[Chunk] = [0x401B00840138013,0x87F640000000002,0xFFFF6FF66FC6FF6,0x8F41C8020FFFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]
static let ROI:[Chunk] = [0x401B00840138012,0x87F640000000002,0xFFFF6FF66FC6FF6,0x8F41C8020FFFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]
static let R2modp:[Chunk] = [0x89118D28DC21038,0x1C24CD524708896,0x96F6AF594FD13D3,0xFC17B3AFB34F599,0x617CBFE0F54B3BC,0x105034B613F1E2,0x47E597791E4CB9,0x12EACA995DA]
static let MConst:Chunk = 0x718CE9E711BB5E5
static let SQRTm3:[Chunk] = [0x402400CC0210022,0x2FEF80000000002,0xFFFF6FF4BFB07F1,0xAEC27C032FFFFFF,0xD81440,0xFF03F5DFD2FFB80,0x23FFFFFFFFFF6,0x24048036012]
static public let Fra:[Chunk] = [0xEE4BE3FF2575D1A,0x180FC7D89659DBD,0x8D90D45D1D93FA1,0x7C0562173310CC7,0x87E11C792504D54,0x72708592ED03A9A,0xB40BCFDB5A8CC11,0x16FF4348CB]
static public let Frb:[Chunk] = [0x2204AE0955FF85B,0x20902388657BEB6,0xD00F94F4BD630A,0xBADB14A1A7A84FF,0xE85F7B00D8E4B1D,0x8325B27493CA001,0xE90EA882008E6B6,0x23C37F80940]

//*** rom curve parameters *****
// Base Bits= 60
// Ate Bits= 118
// G2 Table size= 125

static let CURVE_Cof_I:Int = 1
static public let CURVE_Cof:[Chunk] = [0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static let CURVE_B_I:Int = 5
static public let CURVE_B:[Chunk] = [0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static public let CURVE_Order:[Chunk] = [0x401B007E010800D,0x17F7C0000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]
static public let CURVE_Gx:[Chunk] = [0xC98D91F36B6980D,0x9C0372E5CD70113,0x69A416A0B1E7923,0x4B2E689DB1BBB4E,0x95F63B3EDBEC3CF,0x160B9AC9264B6F,0x191FADBA34A0A3,0x21A6D67EF25]
static public let CURVE_Gy:[Chunk] = [0x8A5734D36FB03DE,0x32C66600622ECAA,0xB8AE40EB80F4754,0x50426E6AF77DF11,0xCCCFA7D788C6596,0x7432A490EEDA842,0x7F7ABB82B33676A,0x118EA0460F]
static public let CURVE_HTPC:[Chunk] = [0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0]
static public let CURVE_Bnx:[Chunk] = [0xFFFFFFFFFFFBFFF,0x4001FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0]
static public let CRu:[Chunk] = [0x401F80A801A401A,0xDBF2E0000000002,0xFFFF6FF597BBBF3,0x9F0222029FFFFFF,0xD81368,0xFF08764BD65FC10,0x23FFFFFFFFFF6,0x24048036012]
static public let CURVE_Pxa:[Chunk] = [0x68E3D934AE1E4DF,0xAA6A8B488076954,0xBAD92E0032AE1F0,0x408208F9AD2699,0x1CD96ED61C91382,0xBDC5482E0337E7C,0x8DDA0DFB38E3A8C,0x257CCC85B5]
static public let CURVE_Pxb:[Chunk] = [0x3108BA6AA8CD283,0x8B59BF7E850E9B7,0x555B783718F50AF,0x58B18134DD86BAE,0x730CBED91768840,0x566BA3C98E2A354,0x99102AF8EDCA849,0x1D2E4343E85]
static public let CURVE_Pya:[Chunk] = [0xE5B68DF0DB7154E,0x140E7B11D7C3376,0xC9DDAE32E03695A,0xFE810F1399A1F41,0x6E23C3FA7A6BB42,0x809ECA03563470,0x22C1979517427A2,0xA0650439DA]
static public let CURVE_Pyb:[Chunk] = [0xA14CC552CA2A93A,0x68D53743493B9EB,0x444A04EF87387AA,0x70FD725CC647692,0x69AC57B393F1AB3,0x6324D44D5E6B0C,0x8CBE0172C8AE373,0x73EF0CBD43]
static let CURVE_W:[[Chunk]] = [[0x60020003,0x7FFF00000000000,0xFFFFFFFFFFFF3FF,0x60060017FFFFF,0x0,0x0,0x0,0x0],[0xFFFFFFFFFFF7FFF,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0]]
static let CURVE_SB:[[[Chunk]]] = [[[0x60028004,0x77FEC0000000000,0xFFFFFFFFFFFF3FF,0x60060017FFFFF,0x0,0x0,0x0,0x0],[0x401B007E011000E,0xFF780000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]],[[0xFFFFFFFFFFF7FFF,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0x60020003,0x7FFF00000000000,0xFFFFFFFFFFFF3FF,0x60060017FFFFF,0x0,0x0,0x0,0x0]]]
static let CURVE_WB:[[Chunk]] = [[0x20004000,0xDBFFE0000000000,0xFFFFFFFFFFFFBFF,0x20020007FFFFF,0x0,0x0,0x0,0x0],[0xFFFCFFE3FFABFFB,0x14029FFFFFFFFFF,0x9008002,0xF53FBFFF9000000,0xFFFFFFFFFFFFF6F,0x30048024005F,0x0,0x0],[0xFFFE7FF1FFD3FFD,0xC015FFFFFFFFFF,0x4804001,0xFA9FDFFFC800000,0xFFFFFFFFFFFFFB7,0x18024012002F,0x0,0x0],[0x2000C001,0xD3FFA0000000000,0xFFFFFFFFFFFFBFF,0x20020007FFFFF,0x0,0x0,0x0,0x0]]
static let CURVE_BB:[[[Chunk]]] = [[[0xFFFFFFFFFFFC000,0x4001FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFFFFFFFFFBFFF,0x4001FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFFFFFFFFFBFFF,0x4001FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0x401B007E011000F,0xFF780000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]],[[0xFFFFFFFFFFF7FFF,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0x401B007E010C00E,0x13F7A0000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012],[0x401B007E010C00D,0x13F7A0000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012],[0x401B007E010C00E,0x13F7A0000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]],[[0xFFFFFFFFFFF7FFE,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFFFFFFFFF7FFF,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFFFFFFFFF7FFF,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0xFFFFFFFFFFF7FFF,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0]],[[0x401B007E010C00F,0x13F7A0000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012],[0x401B007E011800F,0x7F740000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012],[0xFFFFFFFFFFF7FFD,0x8003FFFFFFFFFF,0x0,0x0,0x0,0x0,0x0,0x0],[0x401B007E010C00F,0x13F7A0000000002,0xFFFF6FF66FC7BF7,0x8EE1C201F7FFFFF,0xD81290,0xFF0CF6B7D9BFCA0,0x23FFFFFFFFFF6,0x24048036012]]]

#endif

}

